package com.issue.common.utils.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;

public class ExcelImportListener<T extends BaseImportVo> extends AnalysisEventListener<T> {

    private List<T> data = new ArrayList<>();

    @Override
    public void invoke(T o, AnalysisContext analysisContext) {
        // 去除空格，具体去除方式根据字段确定，防止匹配时出现问题
        if (o != null){
            o.clearTrim();
        }
        data.add(o);
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    /**
     * 解析结束时调用
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }

    public void clearData() {
        data.clear();
    }
}
